﻿using System;
using System.Linq;
using System.Collections.Generic;
using QuickApp;


namespace QuickApp.DbInterface
{
    public abstract class QADbDatabase : IQAParent,IQAChild
    {

        #region Protected Fields

        protected QADbManager dataManager;

        protected String name,displayName;

        protected List<QADbTable> tables;

        #endregion Protected Fields

        #region Public Constructors

        public QADbDatabase(string name,string displayName, QADbManager dataManager)
        {
            this.displayName = displayName;
            this.name = name;
            this.dataManager = dataManager;
        }

        #endregion Public Constructors

        #region Public Properties

        public Dictionary<string, List<IQAChild>> Children
        {
            get
            {
                return new Dictionary<string, List<IQAChild>>() { { "Tables", Tables.Cast<IQAChild>().ToList() } };
            }
        }

        public string Name
        {
            get { return name; }
        }

        public string DisplayName
        {
            get { return displayName; }
        }

        public List<QADbTable> Tables
        {
            get
            {
                if (tables == null)
                    return loadTables();
                return tables;
            }
        }

        #endregion Public Properties

        #region Public Methods

        public abstract string GetSQLDataType();

        #endregion Public Methods

        #region Protected Methods

        protected abstract List<QADbTable> loadTables();

        #endregion Protected Methods

        public override string ToString()
        {
            return DisplayName;
        }
    }
}